package com.ys.erp.entity.data.bean;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import com.ys.erp.common.util.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 南山
 * @date 2025/09/19 15:49
 */
@Data
@TableName(value = "t_activity_turnable")
public class ActivityTurnable {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField(value = "activity_name")
    private String activityName;

    @TableField(value = "activity_status")
    private String activityStatus;

    @TableField(value = "start_time")
    private LocalDateTime startTime;

    @TableField(value = "end_time")
    private LocalDateTime endTime;

    @TableField(value = "background")
    private String background;

    @TableField(value = "exhaust_message")
    private String exhaustMessage;

    @TableField(value = "share_icon")
    private String shareIcon;

    @TableField(value = "my_prize_name_icon")
    private String myPrizeNameIcon;

    @TableField(value = "share_poster")
    private String sharePoster;

    @TableField(value = "join_rule")
    private String joinRule;

    @TableField(value = "qr_code_url")
    private String qrCodeUrl;

    @TableField(value = "redeem_rule")
    private String redeemRule;

    @TableField(value = "version")
    @Version
    private Integer version;

    @TableField(value = "create_time")
    private LocalDateTime createTime;

    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;


    /**
     *
     * 参与规则对应dto对象
     *
     **/
    @Data
    public static class JoinRuleDTO {
        /**
         * 规则类型 ALL_USER_DAY_NUM, ALL_USER_TOTAL_NUM,ADOPT_AND_NOT_ADOPT_USER_NUM
         */
        private String type;

        /**
         * 规则数量
         */
        private List<Siphon> siphonList;
    }

    @Data
    public static class Siphon {
        /**
         * 用户类型 ALL  ADOPT NOT_ADOPT
         */
        private String type;

        /**
         * 抽奖次数
         */
        private Integer num;
    }

    /**
     *
     * 领取规则对应dto对象
     *
     **/
    @Data
    public static class RedeemRuleDTO {
        /**
         * 领取规则类型 NO_OVER_TIME,ACTIVITY_END_OVER_TIME,WINNER_HOUR_OVER_TIME
         */
        private String type;

        private String hour;
    }

    public JoinRuleDTO getJoinRuleDTO() {
        return JSONObject.parseObject(joinRule, JoinRuleDTO.class);
    }

    public RedeemRuleDTO getRedeemRuleDTO() {
        return JSONObject.parseObject(redeemRule, RedeemRuleDTO.class);
    }

    @AllArgsConstructor
    @Getter
    public enum Enums {

        NOT_STARTED,
        ONGOING,
        ENDED,

        ALL_USER_DAY_NUM,
        ALL_USER_TOTAL_NUM,
        ADOPT_AND_NOT_ADOPT_USER_NUM,

        ALL,
        ADOPT,
        NOT_ADOPT,

        NO_OVER_TIME,
        ACTIVITY_END_OVER_TIME,
        WINNER_HOUR_OVER_TIME

    }

    public static final Map<String, String> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.put(Enums.NOT_STARTED.toString(), "未开始");
        ENUM_MAP.put(Enums.ONGOING.toString(), "进行中");
        ENUM_MAP.put(Enums.ENDED.toString(), "已结束");

        ENUM_MAP.put(Enums.ALL_USER_DAY_NUM.toString(), "所有用户每天可以抽多少次");
        ENUM_MAP.put(Enums.ALL_USER_TOTAL_NUM.toString(), "活动可以抽取多少次");
        ENUM_MAP.put(Enums.ADOPT_AND_NOT_ADOPT_USER_NUM.toString(), "领猫和没有领猫用户分别可以抽取多少次");

        ENUM_MAP.put(Enums.ALL.toString(), "所有用户");
        ENUM_MAP.put(Enums.ADOPT.toString(), "领猫用户");
        ENUM_MAP.put(Enums.NOT_ADOPT.toString(), "没有猫咪用户");

        ENUM_MAP.put(Enums.NO_OVER_TIME.toString(), "随时可以兑换");
        ENUM_MAP.put(Enums.ACTIVITY_END_OVER_TIME.toString(), "活动结束前可以兑换");
        ENUM_MAP.put(Enums.WINNER_HOUR_OVER_TIME.toString(), "中奖多少小时后超时");


    }


}


